﻿#ifndef QMAINFORMTITLEBAR_H
#define QMAINFORMTITLEBAR_H

#include <QApplication>
#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGridLayout>

#include <QEvent>
#include <QMouseEvent>
#include <QIcon>
#include <QStyleOption>
#include <QPainter>
#include <QGraphicsView>
#include <QSizePolicy>

#include "QStyleSheetHelper.h"

class QMainFormTitleBar : public QWidget
{
    Q_OBJECT
public:
    explicit QMainFormTitleBar(QWidget *parent = NULL);
    ~QMainFormTitleBar();

    void SetTitleText(QString TitleText);
    void SetTitleIcon(QIcon TitleIcon);
    void SetTitleIcon(QChar Descriptor);

    void SetMinimizeButtonIcon(QChar Descriptor);
    void SetMaximizeButtonIcon(QChar Descriptor);
    void SetCloseButtonIcon(QChar Descriptor);

signals:
    void TitleMouseDoubleClickEvent(QMouseEvent* event);
    void TitleMouseMoveEvent(QMouseEvent *event);
    void TitleMousePressEvent(QMouseEvent *event);
    void TitleMouseReleaseEvent(QMouseEvent *event);

    void ShowMinimized();
    void ShowMaximized();
    void CloseForm();

public slots:
    void resizeEvent(QResizeEvent *event);
    void paintEvent(QPaintEvent* paintEvent);

    // 进行最小化、最大化/还原、关闭操作
    void onClicked();
protected:
    virtual void mouseDoubleClickEvent(QMouseEvent* event);
    virtual void mouseMoveEvent(QMouseEvent *event);
    virtual void mousePressEvent(QMouseEvent *event);
    virtual void mouseReleaseEvent(QMouseEvent *event);
    virtual void moveEvent(QMoveEvent *event);
    virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result);
    virtual bool eventFilter(QObject *watched, QEvent *event);

private:
    QLabel*         FormTitleIconLabel;
    QLabel*         FormTitleTextLabel;

    QPushButton*    FormMinimizeButton;
    QPushButton*    FormMaximizeButton;
    QPushButton*    FormCloseButton;

    QGraphicsView   FormTitleIconView;
    QStyleSheetHelper* StyleSheetHelper;
    QHBoxLayout* TitleIconTextHorizontalLayout;
    QHBoxLayout* TitleButtonHorizontalLayout;
    QWidget* TitleButtonWidget;
};

#endif // QMAINFORMTITLEBAR_H
